#/bin/bash
ISO_FILES="/mnt/Rocky-9.6-x86_64-dvd.iso"
if [ -f "$ISO_FILES" ]; then
    mkdir -p /mnt/iso && mount -o loop $ISO_FILES /mnt/iso && echo "挂载成功！"
else
    echo "上传镜像/mnt/并且mount -o loop /mnt/*.iso /mnt/iso"; exit 1
fi

mkdir -p /etc/yum.repos.d/backup && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
cat > /etc/yum.repos.d/local-iso.repo << EOF
[local-iso-base]
name=Local BaseOS
baseurl=file:///mnt/iso/BaseOS
enabled=1
gpgcheck=0
[local-iso-app]
name=Local AppStream
baseurl=file:///mnt/iso/AppStream
enabled=1
gpgcheck=0
EOF

yum clean all && yum makecache -y

# 新增2：安装sshpass（免密登录依赖）
yum install -y sshpass
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa &> /dev/null
yum install -y ansible-*
for i in {101..109}; do sshpass -p yqt123 ssh-copy-id -o StrictHostKeyChecking=no -f root@192.168.95.$i; done

echo "*/10 * * * * chronyc -a makestep > /dev/null 2>&1 && hwclock -w > /dev/null 2>&1" >> /var/spool/cron/root